<ul class="nav nav-tabs">
	<li ng-class="{'active':pagedata.op=='list'}"><a href="javascript:;" ng-click="access()">自定义页面列表</a></li>
	<li ng-class="{'active':pagedata.op=='edit'}"><a href="javascript:;" ng-click="access('edit')">添加自定义页面</a></li>
	<li ng-if="pagedata.isfounder==1" ng-class="{'active':pagedata.op=='get'}"><a href="javascript:;" ng-click="post({},'get')">同步云端组件库</a></li>
</ul>

<div id="editform" class="form-horizontal form">
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
</style>
<script language="javascript">require(['underscore']);</script>
<script type="text/javascript" src="../core/resource/js/hhSwipe.js"></script>
<script type="text/javascript" src="../core/resource/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="../core/resource/components/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../core/resource/components/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="../core/resource/components/ueditor/ueditor.parse.js"></script>
<script type="text/javascript" src="../core/resource/components/ueditor/lang/zh-cn/zh-cn.js"></script>
<link href="../core/resource/css/designer.css" rel="stylesheet">
<link href="../core/resource/css/web.css?v=1" rel="stylesheet">
<link href="../core/resource/css/diy1.css" rel="stylesheet">
<link href="../core/resource/css/diy2.css" rel="stylesheet">

<link href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet">
        <div class="fe" ng-init="pagedata.index=-1;pagedata.edithtml='pages/edits/main.html';pagedata.editdata=pagedata.item.setting;">
            <div class="fe-phone">
                <div class="fe-phone-left"></div>
                <div class="fe-phone-center">
                    <div class="fe-phone-top"></div>
                    <div class="fe-phone-main">
						<div id="editor" >
							<div class="fe-mod fe-mod-11 fe-mod-nohover">
								<div class="fe-mod-11-title" ng-click="pagedata.edithtml='pages/edits/main.html';pagedata.editdata=pagedata.item.setting">{{pagedata.item.title || '默认标题'}}</div>
							</div>
							<div style="height: 50px;" ng-show="pagedata.item.setting.guide==1"></div>
							<div ng-repeat="inav in pagedata.item.items track by $index" class="fe-mod-repeat" ng-class="{'chose':pagedata.index==$index}">
                                <div ng-include="tomedia(inav.showhtml)" class="fe-mod-parent" ng-click="pagedata.edithtml=inav.edithtml;pagedata.editdata=inav.params;pagedata.index=$index;"></div>
                                <div class="fe-mod-del" ng-show="pagedata.index==$index" ng-click="pagedata.item.items.splice($index,1)">移除</div>
                            </div>
                            <!-- 浮动按钮 -->
                            <div class="fe-floatico" ng-show="pagedata.item.setting.fudong==1" ng-style="{'width':pagedata.item.setting.fstyle.width,'top':pagedata.item.setting.fstyle.top}" ng-class="{'fe-floatico-right':pagedata.item.setting.fstyle.style=='right'}">
                                <img ng-src="{{pagedata.item.setting.fstyle.img || '../core/resource/images/init-data/init-image-7.png'}}" style="height:100%; width: 100%;"/>
                            </div>
                            <!-- 关注按钮 -->
                            <div class="fe-guide" ng-show="pagedata.item.setting.guide==1" ng-style="{'display':'block','background-color':pagedata.item.setting.gstyle.bgcolor,'top':'60px','z-index':'890','opacity':pagedata.item.setting.gstyle.opacity}">
                                <div class="fe-guide-faceimg"><img ng-src="../core/resource/images/init-data/init-icon.png" ng-style="{'border-radius':pagedata.item.setting.gstyle.facestyle}" /></div>
                                <div class="fe-guide-sub" ng-style="{'color':pagedata.item.setting.gstyle.navcolor,'background-color':pagedata.item.setting.gstyle.navbgcolor}">{{pagedata.item.setting.gstyle.sub ||'立即关注'}}</div>
                                <div class="fe-guide-text"  ng-style="{'font-size':pagedata.item.setting.gstyle.size,'color':pagedata.item.setting.gstyle.color}">
                                    <p ng-class="{'fe-guide-lineheight':pagedata.item.setting.gstyle.title2==''}">{{pagedata.item.setting.gstyle.title1s || '加关注，做代理。'}}</p>
                                    <p ng-class="{'fe-guide-lineheight':pagedata.item.setting.gstyle.title1==''}">{{pagedata.item.setting.gstyle.title2s || '关注公众号，享专属服务'}}</p>
                                </div>
                            </div>
						</div>
                    </div>
                    <div class="fe-phone-bottom"></div>
                </div>
                <div class="fe-phone-right"></div>
            </div>
            <div class="fe-panel">
                <div style="width:550px;height:150px">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 left-label">素材名称</label>
						<div class="col-sm-6 col-md-8 col-lg-8">
							<input type="text" class="form-control" name="title" id="title" value="" />
						</div>
						<div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
							<button id="submit" ng-click="getnav()" class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
						</div>
					</div>
					<div>
					<button ng-show="nav.title" ng-repeat="nav in pagedata.navs" ng-click="new={'nid':nav.cloud_id,'showhtml':nav.showhtml,'edithtml':nav.edithtml,'params':{}};pagedata.item.items.splice(pagedata.index+1,0,new);pagedata.edithtml=nav.edithtml;pagedata.editdata=pagedata.item.items[pagedata.index+1].params;pagedata.index=pagedata.index+1;" class="btn btn-default" style="float: left;"> {{nav.title}}</button>
					</div>
				</div>
				<div style="width:550px;height:350px" class="diy-editor" ng-include="tomedia(pagedata.edithtml)" onload="func.start()"></div>
            </div>
        </div>
        <!-- 页面底部保存栏 -->
        <div class="fe-save">
            <div class="fe-save-main">
                <div class="fe-save-submit save-submit" ng-click="post(pagedata.item,'postmade')">保存</div>
               
            </div>
            <div class="fe-save-fold" onclick="fold()"></div>
            <div class="fe-save-gotop" onclick="$(document.body).animate({scrollTop:0},500)"><i class="fa fa-angle-up"></i><br>返回顶部</div>
        </div>
</div>
<div id="floating-data"  class="modal fade" tabindex="-1" style="z-index:99999;display:none">
    <div class="modal-dialog" style='width: 920px;'>
        <div class="modal-content">
            <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择数据</h3></div>
					<div class="mylink-con">
						<div class="page-header">
                            <h4><i class="fa fa-folder-open-o"></i>主表字段</h4>
                        </div>
						<div ng-repeat="v in pagedata.data.fields" ng-click="getdata(v.name)" class="btn btn-default mylink-nav" >{{v.title}}</div>
					</div>
					<div class="mylink-con">
						<div class="page-header">
                            <h4><i class="fa fa-folder-open-o"></i>父表字段</h4>
                        </div>
						<div ng-repeat="v in pagedata.data.father" ng-click="getdata('father.'+v.name)" class="btn btn-default mylink-nav" >{{v.title}}</div>
					</div>
					<div class="mylink-con" ng-repeat="fu in pagedata.data.more" ng-if="pagedata.data.more" >
						<div class="page-header">
                            <h4><i class="fa fa-folder-open-o"></i>附表{{fu.title}}字段</h4>
                        </div>
						<div ng-repeat="v in fu.fields" ng-click="getdata(fu.name+'.'+v.name)" class="btn btn-default mylink-nav" >{{v.title}}</div>
					</div>
					<div class="mylink-con" ng-if="pagedata.data.sun" >
						<div class="page-header">
                            <h4><i class="fa fa-folder-open-o"></i>选择子表数据</h4>
                        </div>
						<div ng-repeat="su in pagedata.data.sun" ng-click="getdata(su.name)" class="btn btn-default mylink-nav" >{{su.title}}</div>
					</div>
            <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
        </div>
    </div>
</div>
<div id="sun-data"  class="modal fade" tabindex="-1" style="z-index:99999;display:none">
    <div class="modal-dialog" style='width: 920px;'>
        <div class="modal-content">
            <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择数据</h3></div>
					<div class="mylink-con">
						<div class="page-header">
                            <h4><i class="fa fa-folder-open-o"></i>选择子表数据</h4>
                        </div>
						<div ng-repeat="v in pagedata.data.sun[pagedata.sun_name].fields" ng-click="getdata(v.name,1)" class="btn btn-default mylink-nav" >{{v.title}}</div>
					</div>
            <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
        </div>
    </div>
</div>
<script>
	function fold(){
        width= $(".fe-save").width();
        left = $(".fe-save").css("left");
        left = left.replace("px","");
        if(left>=0){
            $(".fe-save").animate({left:0-width+40+"px"},1000);
            $(".fe-save-fold").addClass("fe-save-fold2");
        }else{
            $(".fe-save").animate({left:"0px"},1000);
            $(".fe-save-fold").removeClass("fe-save-fold2");
        }
    }
	window.scope.getnav=function(){
		var key=$('#title').val();
		if(key){
			window.scope.post({},'getnav','title='+key,function(result){
				window.scope.pagedata.navs=result;
				window.scope.$apply();
			});
		}else{
			window.scope.post({},'getnav','',function(result){
				window.scope.pagedata.navs=result;
				window.scope.$apply();
			});
		}
		
	}
	window.scope.lunbo=function(){
		$('.fe-mod-2 .swipe').each(function(){
                        initswipe($(this));
        })
        $('.fe-mod-8-main-img img').each(function(){
            $(this).height($(this).width());    
        });
        $('.fe-mod-12 img').each(function(){
            $(this).height($(this).width());    
        });
	}
	//设置数据
	window.scope.choosedata=function(to,field){
		window.scope.currentmodel=to;
		window.scope.currentfield=field;
		$('#floating-data').modal();
	}
	//读取数据
	window.scope.getdata=function(data,is_sun){
		window.scope.currentmodel[currentfield]=data;
		if(is_sun){
			$('#sun-data .close').click();
		}else{
			$('#floating-data .close').click();
		}
		
	}
	//读取设置子表字段
	window.scope.choose_sun_data=function(to,field,f){
		window.scope.currentmodel=to;
		window.scope.currentfield=field;
		var temp=f.split('.');
		window.scope.pagedata.sun_name=temp['1'];
		$('#sun-data').modal();
	}
	window.scope.func.start=function(){
		//初始化slider
		$('.slider').each(function(){
			var min=$(this).attr('data-min');
			var max=$(this).attr('data-max');
			var model=$(this).attr('data-model');
			var def=$(this).attr('data-default');
			var step=$(this).attr('data-step');
			if(!min){
				min=0;
			}
			if(!def){
				def=min;
			}
			if(!model){
				return false;
			}
			if(!step){
				step=1;
			}
			$(this).slider({
				slide:function(event,ui){
						eval('window.scope.'+model+'='+ui.value+';');
						window.scope.$apply();
					},
				value:def,
				min:min,
				max:max,
				step:step
			});
		});
	}
</script>
